package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.utils.ConvertUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.params.SysLanguageDataParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysLanguageDataMapper;
import com.ruoyi.system.domain.SysLanguageData;
import com.ruoyi.system.service.ISysLanguageDataService;

/**
 * 语言翻译Service业务层处理
 *
 * @author ruoyi
 * @date 2022-04-26
 */
@Service
public class SysLanguageDataServiceImpl implements ISysLanguageDataService {
    @Autowired
    private SysLanguageDataMapper languageDataMapper;

    /**
     * 查询语言翻译
     *
     * @param id 语言翻译主键
     * @return 语言翻译
     */
    @Override
    public SysLanguageData selectSysLanguageDataById(Long id) {
        return languageDataMapper.selectSysLanguageDataById(id);
    }

    @Override
    public Page<SysLanguageData> selectSysLanguageDataList(Page<SysLanguageData> page, SysLanguageData sysLanguageData) {
        return languageDataMapper.selectSysLanguageDataList(page,sysLanguageData);
    }

    @Override
    public int insertSysLanguageData(SysLanguageDataParams sysLanguageData) {
        SysLanguageData languageData = ConvertUtil.sourceToTarget(sysLanguageData, SysLanguageData.class);
        languageData.setValue(JSONUtil.toBean(sysLanguageData.getValue(), Map.class));
        languageData.setCreateBy(SecurityUtils.getUsername());
        return languageDataMapper.insertSysLanguageData(languageData);
    }

    @Override
    public int updateSysLanguageData(SysLanguageData sysLanguageData) {
        sysLanguageData.setUpdateBy(SecurityUtils.getUsername());
        return languageDataMapper.updateSysLanguageData(sysLanguageData);
    }

    @Override
    public int deleteSysLanguageDataById(Long id) {
        return languageDataMapper.deleteSysLanguageDataById(id);
    }

    @Override
    public SysLanguageData selectByRef(Long refId, String refType) {
        Locale locale = LocaleContextHolder.getLocale();
        return languageDataMapper.selectByRef(refId,refType,locale.getLanguage());
    }

}